package action.AZ20;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import services.AZ20.AZ20Services;
import com.PublicSystem;
import com.syslog.SysLogServices;
import com.util.Component;
import com.util.Util;
/**
 * 领卡相关操作Action
 * @author duy
 *
 */
@Controller
@RequestMapping("AZ20.do")
public class AZ20Action {
	SysLogServices log = SysLogServices.getInstance();
	PublicSystem sys = PublicSystem.getInstance();
	AZ20Services ss = new AZ20Services();
	/**
	* 查询批次信息
	* @author duy
	* @param request
	* @param response
	*@throws Exception
	*/ 
	@RequestMapping(params = "method=getAZ20")
	public void getAZ20(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
		String aae008 = Component.getQuest("aae008", request);
		String userid = Component.getSession("userid", request);
	    HashMap parms = sys.getGridSort(request);
	    String json = Util.Encode(ss.getAZ20(new Object[] {aaz001, aae008}, parms));
	    HashMap obj = new HashMap();
		obj.put("domainid", "SBK");   //分系统号，见sys_log_bm
		obj.put("log_type", "T05");   //日志类别，见sys_log_bm
		obj.put("userid", userid);    //操作人
		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		obj.put("content", "制卡批次为：" + aaz001 + "的制卡数据生成");  //日志内容，自己组合拼装
		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm 
		obj.put("datain","制卡批次为：" + aaz001 + "银行：" + aae008); //输入参数
		obj.put("dataout", "success");//输出参数
		log.sysLogMap(obj, request);
	    Component.print(json, response);
	}
	
	/**
	* 查询批次信息（导出）
	* @author duy
	* @param request
	* @param response
	*@throws Exception
	*/ 
	@RequestMapping(params = "method=getAZ201")
	public void getAZ201(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
		String aae008 = Component.getQuest("aae008", request);
	    HashMap parms = sys.getGridSort(request);
	    String json = Util.Encode(ss.getAZ201(new Object[] {aaz001, aae008}, parms));
	    Component.print(json, response);
	}
	/**
	* 查询各网点领卡银行
	* @author duy
	* @param request
	* @param response
	*@throws Exception
	*/ 
	@RequestMapping(params = "method=getbank")
	public void getbank(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
	    HashMap parms = sys.getGridSort(request);
	    String json = Util.Encode(ss.getbank(new Object[] {aaz001}, parms));
	    Component.print(json, response);
	}
	/**
	* 查询各网点领卡数量
	* @author duy
	* @param request
	* @param response
	*@throws Exception
	*/ 
	@RequestMapping(params = "method=getlksl")
	public void getlksl(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
		String lklx = Component.getQuest("lklx", request);
		String aaz730 = Component.getQuest("aaz730", request);
		HashMap json = ss.getlksl(aaz001, lklx, aaz730);
	    Component.print(json, response);
	}
	/**
	 * 领卡类型
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=getlksl1")
	public void getlksl1(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
		String lklx = Component.getQuest("lklx", request);
		String aaz730 = Component.getQuest("aaz730", request);
	    String json = Util.Encode(ss.getlksl1(aaz001, lklx, aaz730));
	    Component.print(json, response);
	}
	/**
	 * 领卡登记查询
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=setlkdj")
	public void setlkdj(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
		String lklx = Component.getQuest("lklx", request);
		String aaz730 = Component.getQuest("aaz730", request);
		String aaz7301 = Component.getQuest("aaz7301", request);
		String aae011 = Component.getQuest("aae011", request);
		String id = Component.getQuest("id", request);
	    String result = ss.setlkdj(aaz001, lklx, aaz730, aaz7301, aae011, id);
	    Component.print(result, response);
	}
	/**
	* 数据导出
	* @author duy
	* @param request
	* @param response
	* @throws Exception
	*/
	@RequestMapping(params = "method=ExpAZ20")
	public void ExpAZ20(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
		String aae008 = Component.getQuest("aae008", request);
		HashMap parms = sys.getGridSort(request);
	    File f = ss.ExpAZ20(new Object[] {aaz001, aae008}, parms, response);
	    String userid = Component.getSession("userid", request);
	    HashMap obj = new HashMap();
		obj.put("domainid", "SBK");    //分系统号，见sys_log_bm
		obj.put("log_type", "T06");    //日志类别，见sys_log_bm
		obj.put("userid", userid);     //操作人
		obj.put("rwh", Component.getSession("rwid", request));	       //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		obj.put("content", "制卡批次为：" + aaz001 + "的制卡数据导出");  //日志内容，自己组合拼装
		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
		obj.put("datain", "制卡批次为：" + aaz001 + "银行：" + aae008);     //输入参数
		obj.put("dataout", "success");//输出参数
		log.sysLogMap(obj, request);
	    Util.downLoadData(response, f, "export.zip");
	}
	/**
	 * 生成批次信息
	 * @author duy 
	 * @param request
	 * @param response
	 *@throws Exception
	 */
	@RequestMapping(params = "method=saveAZ20")
	public void saveAZ20(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String json = request.getParameter("data");
		ArrayList rows = (ArrayList)Util.Decode(json);
		HashMap row = (HashMap)rows.get(0);
		row.remove("pagesize");
		String userid = Component.getSession("userid", request);
		row.put("aae011", userid);     //经办人员号
		String a=ss.insertAZ20(row);
		Component.print(a, response);
		HashMap obj = new HashMap();
		obj.put("domainid", "SBK");   //分系统号，见sys_log_bm
		obj.put("log_type", "T02");   //日志类别，见sys_log_bm
		obj.put("userid", userid);    //操作人
		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		obj.put("content", "制卡批次为：" + row.get("aaz001").toString() + "的制卡数据生成");  //日志内容，自己组合拼装
		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
		obj.put("datain", json);      //输入参数
		obj.put("dataout", a);//输出参数
		log.sysLogMap(obj, request);
	}
	/**
	 * 获取下拉列表数据
	 * @author duy 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=getselect")
	public void getSelect(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List data = ss.getSelect(Component.getQuest("AAA100", request));
    	Component.print(Util.Encode(data), response);
	}
	/**
	 * 银行下拉框选项
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=getyinhang")
	public void getYinhang(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List data = ss.getYinhang(Component.getQuest("sj", request));
		Component.print(Util.Encode(data), response);
	}	
	/**
	 * 校验导入
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=checkkcdata")
	public void checkkcdata(HttpServletRequest request, HttpServletResponse response) throws Exception {		
		String json = request.getParameter("data");
		ArrayList rows = (ArrayList)Util.Decode(json);		
		HashMap row = (HashMap)rows.get(0);	
		String key = row.get("eventid").toString();
		String eventid = "";
		if(key.contains(">")) {
			String[]  str = key.split(">");
			eventid = str[1].substring(0,str[1].lastIndexOf("<"));
			row.put("eventid", eventid);
			}
		HashMap checkkreturn = ss.checkkcdata(row);		
	    Component.print(Util.Encode(checkkreturn), response);
	} 
	/**
	 * 登记回盘数据
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=savekcdata")
	public void savekcdata(HttpServletRequest request, HttpServletResponse response) throws Exception {		
		String json = request.getParameter("datas");
		ArrayList rows = (ArrayList)Util.Decode(json);		
		HashMap row = (HashMap)rows.get(0);	
		String aae011 = Component.getSession("userid", request);
		row.put("aae011", aae011);
		String inreturn = ss.savekcdata(row);		
		String userid = Component.getSession("userid", request);
		if(inreturn == "0") {
			HashMap obj = new HashMap();
			obj.put("domainid", "SBK");   //分系统号，见sys_log_bm
			obj.put("log_type", "T02");   //日志类别，见sys_log_bm
			obj.put("userid", userid);    //操作人
			obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
			obj.put("content", "制卡批次为：" + row.get("aaz001").toString() + "的数据导入");  //日志内容，自己组合拼装
			obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
			obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
			obj.put("datain", json);      //输入参数
			obj.put("dataout", "success");//输出参数
			log.sysLogMap(obj, request);
		} else {
			HashMap obj = new HashMap();
			obj.put("domainid", "SBK");   //分系统号，见sys_log_bm
			obj.put("log_type", "T02");   //日志类别，见sys_log_bm
			obj.put("userid", userid);    //操作人
			obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
			obj.put("content", "制卡批次为：" + row.get("aaz001").toString() + "的数据导入");  //日志内容，自己组合拼装
			obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
			obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
			obj.put("datain", json);      //输入参数
			obj.put("dataout", "error");  //输出参数
			log.sysLogMap(obj, request);
		}
	    Component.print(Util.Encode(inreturn), response);
	} 
	/**
	* 卡厂回盘数据数据导出
	* @author duy
	* @param request
	* @param response
	* @throws Exception
	*/
	@RequestMapping(params = "method=exkcdate")
	public void exkcdate(HttpServletRequest request, HttpServletResponse response) throws Exception {	
		String eventid = Component.getQuest("eventid", request);
	    File f = ss.exkcdate(eventid);
	    String userid = Component.getSession("userid", request);
	    HashMap obj = new HashMap();
		obj.put("domainid", "SBK");   //分系统号，见sys_log_bm
		obj.put("log_type", "T06");   //日志类别，见sys_log_bm
		obj.put("userid", userid);    //操作人
		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		obj.put("content", "错误数据文件导出");  //日志内容，自己组合拼装
		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
		obj.put("datain", "");        //输入参数
		obj.put("dataout", "success");//输出参数
		log.sysLogMap(obj, request);
	    Util.downLoadData(response, f, "sjhp_error" + eventid + ".xls");
	}
	/**
	* 查询回卡信息
	* @author duy
	* @param request
	* @param response
	*@throws Exception
	*/ 
	@RequestMapping(params = "method=gettemp")
	public void gettemp(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = Component.getQuest("id", request);			
	    HashMap parms = sys.getGridSort(request);
	    String json = Util.Encode(ss.gettemp(new Object[] {id}, parms));
	    Component.print(json, response);
	}
}